﻿using Caliburn.Micro;
using System;
using WebSocketSharp;
using WebSocketSharp.Server;

namespace Sun.WebSocket.SerialPort.Center
{
  public class WsBoxWebSocketBehavior : WebSocketBehavior
  {
    public WsBoxWebSocketBehavior()
    {
      _EventAggregator = IoC.Get<IEventAggregator>();
    }

    private readonly IEventAggregator _EventAggregator;

    protected override void OnMessage(MessageEventArgs e)
    {
      if (e.IsBinary || e.IsText)
      {
        _EventAggregator.MessageOnUiThread(new WsDataMsg(e.IsBinary, e.Data, e.RawData));
      }
      base.OnMessage(e);
    }
  }
}